#include "SuccessScene.h"
#include "EndPageScene.h"


USING_NS_CC;
using namespace ui;
using namespace cocostudio;

Scene* Success::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = Success::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool Success::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    
	auto rootNode = CSLoader::createNode("SuccessScene.csb");
	addChild(rootNode);
	auto btn1 = dynamic_cast<Button*>(rootNode->getChildByName("Button_1"));
	struct callBackFunctor {
		void operator() (Ref* sender) const {
			Director::getInstance()->replaceScene(TransitionCrossFade::create(.2f, EndPage::createScene()));
		}
	};
	Widget::ccWidgetClickCallback callback = callBackFunctor();
	btn1->addClickEventListener(callback);



    return true;
}


void Success::menuCloseCallback(Ref* pSender)
{
    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}
